import { defineStore } from "pinia";
const InventoryManagement = [
  { label: "入库管理", path: "IMput" },
  { label: "出库管理", path: "IMout" },
  { label: "盘点管理", path: "IMcheck" },
  { label: "借调登记", path: "IMborrow" },
  { label: "归还管理", path: "IMreturn" },
];
const ApprovalManagement = [
  { label: "入库审批", path: "APput" },
  { label: "出库审批", path: "APout" },
  { label: "盘点审批", path: "APcheck" },
  { label: "借调审批", path: "APborrow" },
];
const LossReportedManagement = [
  { label: "报损管理", path: "LRM" },
  { label: "核销管理", path: "LRcheck" },
];
const LossReportingApproval = [
  { label: "报损审批", path: "LRapprove" },
  { label: "核销审批", path: "LRcheckapprove" },
];
export const useActivePageStore = defineStore(
  "activePage",
  () => {
    let activePage = ref("home");
    let list: any = [];
    let activeList: any = reactive({ list });

    const setActivePage = (page: string) => {
      activePage.value = page;
      switch (page) {
        case "InventoryManagement":
          activeList.list = InventoryManagement;
          break;
        case "ApprovalManagement":
          activeList.list = ApprovalManagement;
          break;
        case "LossReportedManagement":
          activeList.list = LossReportedManagement;
          break;
        case "LossReportingApproval":
          activeList.list = LossReportingApproval;
          break;
      }
      console.log("activeList", activeList.list);
    };
    return { setActivePage, activePage, activeList };
  },
  // TODO: 持久化
  {
    // 配置持久化
    persist: {
      // 调整为兼容多端的API
      storage: {
        setItem(key, value) {
          uni.setStorageSync(key, value);
        },
        getItem(key) {
          return uni.getStorageSync(key);
        },
      },
      paths: ["activePage", "activeList"],
    },
  }
);
